<template>
  <Crumbs :title="'Dispute'" />
  <el-card shadow="hover" class="box-card tinformationTab">
    <div class="m-b40">
      <OrderStep :step="step" />
    </div>

    <div v-if="step === 1">
      <el-form
        label-position="top"
        label-width="100px"
        :model="stepForm"
        style="max-width: 460px"
        :rules="rules"
        ref="ruleFormRef"
      >
        <el-form-item label="Type" prop="type">
          <el-radio-group v-model="stepForm.type">
            <el-radio label="Resended" />
            <el-radio label="Refunded" />
            <el-radio label="Calcel" />
          </el-radio-group>
        </el-form-item>

        <el-form-item label="Reason" prop="reason">
          <el-select v-model="stepForm.reason" placeholder="Please Select">
            <el-option label="Request for Cancellation" :value="0" />
            <el-option label="Request for Refund" :value="1" />
            <el-option label="Request for Resend" :value="2" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="danger" @click="submitForm(ruleFormRef)"
            >Next</el-button
          >
        </el-form-item>

        <!--  -->
      </el-form>
    </div>

    <DisputeTable :type="route.query.type" v-if="step === 2" />
  </el-card>
</template>
<script lang="ts" setup>
import Crumbs from "@/components/Crumbs/index.vue";
import DisputeTable from "./components/DisputeTable.vue";
import { provide, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import type { FormInstance, FormRules } from "element-plus";
import OrderStep from "@/components/OrderStep/index.vue";
import { useRoute } from "vue-router";

// const labelPosition = ref("right");

const step = ref(1);
provide("step", step);

const ruleFormRef = ref<FormInstance>();

const route = useRoute();
console.log(route.query);
const stepForm = reactive({
  type: "",
  reason: "",
});
provide("stepForm", stepForm);

const rules = reactive<FormRules<RuleForm>>({
  type: [
    {
      required: true,
      message: "Please select activity type",
      trigger: "change",
    },
  ],
  reason: [
    {
      required: true,
      message: "Please select Activity zone",
      trigger: "change",
    },
  ],
});

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      ElMessage(`提交值：type：${stepForm.type},reason:${stepForm.reason}`);
      step.value = 2;
    } else {
      ElMessage(`err`);
    }
  });
};
</script>
<style lang="scss" scoped>
.tinformationTab {
  margin: 20px 0;
}
::v-deep .el-input__wrapper {
  width: 300px;
}
::v-deep .el-tabs__nav-wrap {
  margin-bottom: -3px; //-3px
}
::v-deep .el-tabs__active-bar {
  bottom: 2px;
}
</style>
